﻿using SYS.Web.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;

namespace SYS.Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            siteConfig.RegSkin();
        }
        protected void Application_Error(object sender, EventArgs e)
        {
            //Exception exception = Server.GetLastError();

            //throw exception;

            //Response.Clear();

            //HttpException httpException = exception as HttpException;

            //RouteData routeData = new RouteData();

            //if (httpException == null)
            //{
            //}
            //else //It's an Http Exception, Let's handle it.
            //{
            //    switch (httpException.GetHttpCode())
            //    {
            //        case 404:
            //            // Page not found.
            //            routeData.Values.Add("ErrorController", "HttpError404");
            //            break;
            //        case 500:
            //            // Server error.
            //            routeData.Values.Add("ErrorController", "HttpError500");
            //            break;

            //        // Here you can handle Views to other error codes.
            //        // I choose a General error template  
            //        default:
            //            routeData.Values.Add("ErrorController", "General");
            //            break;
            //    }
            //}

            //// Pass exception details to the target error View.
            //routeData.Values.Add("error", exception);

            //// Clear the error on server.
            //Server.ClearError();

            //// Avoid IIS7 getting in the middle
            //Response.TrySkipIisCustomErrors = true;

            //// Call target Controller and pass the routeData.
            //IController errorController = new ErrorController();
            //errorController.Execute(new RequestContext(
            //     new HttpContextWrapper(Context), routeData));
        }

    }
}